//-----------------------------------------------------------
//
//-----------------------------------------------------------
class LightsaberW extends KFMeleeGun;

#exec OBJ LOAD FILE=KF_Weapons2_Trip.ukx

var bool bIsThrown;
var float NextIronTime;

simulated function BeginPlay()
{
	LinkSkelAnim(MeshAnimation'katana_anim');
	Super.BeginPlay();
}

replication
{
	reliable if(Role < ROLE_Authority)
        saberThrow, forcePush;

	reliable if(Role == ROLE_Authority)
		NextIronTime;
}

simulated function Timer()
{
	Super.Timer();
	if (Instigator != None && ClientState == WS_Hidden)
	{
		LightType = LT_None;
	}
	else
		LightType = LT_SubtlePulse;

}

/*function WeaponFire
{
	local KFPlayerReplicationInfo KFPRI;
	
	KFPRI = KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo);
	if (KFPRI != none)
	{
		if (KFPRI.ClientVeteranSkill == Class'Jedi')
		FireModeClass(0)=Class'daforce.litesaberfire';
		FireModeClass(1)=Class'daforce.litesaberfireB';
	}
	else
		FireModeClass(0)=Class'kfmod.katanafire';
		FireModeClass(1)=Class'kfmod.katanafireB';
		
	return Super.Weapon;
}*/

simulated exec function ToggleIronSights()
{
	//local KFPlayerReplicationInfo KFPRI;
	
	//this functionality is available to berserkers only
	//KFPRI = KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo);

	if (        
		!FireMode[0].bIsFiring && FireMode[0].NextFireTime < Level.TimeSeconds &&
		!FireMode[1].bIsFiring && FireMode[1].NextFireTime < Level.TimeSeconds
		)
	{
		saberThrow();
	}
	
/* 	if (NextIronTime <= Level.TimeSeconds &&
		!FireMode[0].bIsFiring && FireMode[0].NextFireTime < Level.TimeSeconds &&
		!FireMode[1].bIsFiring && FireMode[1].NextFireTime < Level.TimeSeconds
		)
	{        
		//forcePush();                
		NextIronTime=Level.TimeSeconds+1.0;
	} */
}


simulated function saberThrow()
{
	local rotator PointRot;
	PointRot = Instigator.GetViewRotation();
	Spawn(Class'LightsaberThrowW',,,Instigator.location,PointRot);
}


simulated function forcePush()
{       
	local rotator PointRot;
	PointRot = Instigator.GetViewRotation();
	Spawn(Class'LightsaberPushW',,,Instigator.location + 72 * Vector(PointRot) + vect(0,0,1) * 15);
	//Spawn(Class'LightsaberPush',,,Instigator.location + (72 * Vector(PointRot)));
}

simulated event RenderOverlays(Canvas Canvas)
{
	Super.RenderOverlays(Canvas);
	
	Canvas.Style = 255;

	//Draw some text.
	Canvas.Font = Canvas.SmallFont;
	Canvas.SetDrawColor(200,150,0);

	Canvas.SetPos(Canvas.SizeX * 0.5, Canvas.SizeY * 0.1);
	if (Level.TimeSeconds < NextIronTime)
		Canvas.DrawText( String(Int(NextIronTime - Level.TimeSeconds)) );
}

simulated function ForceCD() //Called when picked up to prevent bypassing the cooldown.
{
	// If No iron Sight time has been added, add our min 30.0
	// Dont add offset.
/*      if( (NextIronTime-Level.TimeSeconds) >= 7.0 )
	{
		NextIronTime = Level.TimeSeconds;
	}
	
	else if( (NextIronTime-Level.TimeSeconds) > 0 && (NextIronTime-Level.TimeSeconds) < 30.0 )
	{
		// Do Nothing with NextIronTime. (Happens when were picking up the item off the ground while cooling down)
		NextIronTime = Level.TimeSeconds;
	}
	
	else */ 
	if( NextIronTime <= Level.TimeSeconds )
		NextIronTime = Level.TimeSeconds+0.0;         
	return;
}

defaultproperties
{
     weaponRange=90.000000
     BloodyMaterial=Combiner'KF_Weapons2_Trip_T.melee.Katana_Bloody_cmb'
     BloodSkinSwitchArray=0
     bSpeedMeUp=True
     Weight=4.000000
     StandardDisplayFOV=75.000000
     TraderInfoTexture=Texture'KillingFloor2HUD.Trader_Weapon_Icons.Trader_Katana'
     bIsTier3Weapon=True
     SelectSoundRef="Lightsaber_SN.Weapon_Lightsaber.SaberOn"
     HudImageRef="KillingFloor2HUD.WeaponSelect.katana_unselected"
     SelectedHudImageRef="KillingFloor2HUD.WeaponSelect.Katana"
     FireModeClass(0)=Class'PerksSimHostOrg.LightsaberFireW'
     FireModeClass(1)=Class'PerksSimHostOrg.LightsaberFireBW'
     AIRating=0.400000
     CurrentRating=0.600000
     Description="An incredibly hot sword."
     DisplayFOV=75.000000
     Priority=110
     GroupOffset=4
     PickupClass=Class'PerksSimHostOrg.LightsaberPickupW'
     BobDamping=8.000000
     AttachmentClass=Class'PerksSimHostOrg.LightsaberAttachment'
     IconCoords=(X1=246,Y1=80,X2=332,Y2=106)
     ItemName="LightsaberW"
     LightType=LT_None
     LightHue=170
     LightSaturation=155
     LightBrightness=300.000000
     LightRadius=7.000000
     bDynamicLight=True
     Mesh=SkeletalMesh'Lightsaber_A.Weapon_Lightsaber'
     Skins(0)=Combiner'KF_Weapons2_Trip_T.Special.MP_7_cmb'
     Skins(2)=Shader'Lightsaber_T.Weapon_Lightsaber.Lightsaber_shd'
}
